<template>
  <div id="topSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="创建时间:" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="enable">
          <el-select v-model="formInline.enable">
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="searchStr">
          <el-input
            v-model="formInline.searchStr"
            placeholder="请输入群ID/名称搜索"
          >
          </el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            搜索
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TopSearch',
  msg: '人群管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          createTime: '',
          searchStr: '',
          enable: '',
          startTime: '',
          endTime: ''
        }
      }
    }
  },
  data() {
    return {
      statusList: [
        { dictLabel: '所有', dictValue: '' },
        { dictLabel: '启用', dictValue: true },
        { dictLabel: '停用', dictValue: false }
      ]
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {},
  methods: {
    /* 搜索 */
    toSearch() {
      this.$emit('toSearch')
    },
    /* 重置 */
    reset() {
      this.$refs.ruleForm.resetFields()
    }
  }
}
</script>

<style lang="less">
#topSearch {
  .search-box {
    padding-left: 30px !important;
  }
}
</style>
